<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8" />
		<link rel="stylesheet" type="text/css" href="../../../Themes/default/easyui.css">
		<link rel="stylesheet" type="text/css" href="../../../Themes/icon.css">
		<link rel="stylesheet" type="text/css" href="../../../CSS/demo.css">
		<link rel="stylesheet" type="text/css" href="../../../CSS/common.css">
		<script type="text/javascript" src="../../../JS/jquery.min.js"></script>
		<script type="text/javascript" src="../../../JS/jquery.easyui.min.js"></script>
		<script type="text/javascript" src="../../../JS/common.js"></script>
		<script type="text/javascript" src='../../../JS/SHA-1.js'></script>
		<script type="text/javascript" src='../../../JS/json2.js'></script>
		<style type="text/css">
			.button-group {
				width: 100px;
				margin-left: 10px;
			}
		</style>
	</head>
	</style>

	<body>
		<div class="easyui-layout " style="width:460px;height:300px;position:relative;margin:0 auto;">
			<div data-options="region:'center',title:'信息'">
				<div id="dl" style="width: 100%;height:200px;"></div>
				<!--<div class="easyui-datalist" lines="true" checkbox="true" id="dg" title="Data Options" style="width:100%;height:250px" data-options="
            url: 'http://222.196.35.35:9080/GSMarketWebApp/market/regiontype/list.do',method: 'get' ,valueField:'REGIONTYPE_ID',textField:'NAME'">
					</div>-->
				<div style="margin-top: 20px;margin-left: 40px;">
					<input class="easyui-textbox" data-options="required:true" id="ipt" style="width:150px;"></input>
					<input type="button" onclick="SaveData()" id="add" value="添加" class="button-group" />
					<input type="button" name="detele" onclick="destroy()" id="delete" value="删除" class="button-group" />
				</div>
			</div>
		</div>
	</body>
	<script type="text/javascript">
		//		var _type = getID();
		var _type = "providertype";
		var _listaddr;
		var _deleteaddr;
		var _saveaddr;
		var _title;
		var _id;
		var _tname;
		getAddr();
		loadData();

		function getAddr() {
			for(var i = 0; i < typeOptions.length; i++) {
				if(typeOptions[i].type == _type) {
					_listaddr = typeOptions[i].list;
					_saveaddr = typeOptions[i].save;
					_deleteaddr = typeOptions[i].del;
					_title = typeOptions[i].title;
					_id = typeOptions[i].id;
					_tname = typeOptions[i].name;
				}
			}
		}

		function loadData() {
			var _url = RemoteLinkAddress + _listaddr;
			$('#dl').datalist({
				url: _url,
				method: 'get',
				valueField: _id,
				textField: _tname,
				lines: true,
				checkbox: true,

			});

		}
		var auth = "admin;" + hex_sha1("admin1");

		function doSearch(value, name) {
			alert('Your input: ' + value + '(' + name + ')');
		}

		function SaveData() {
			var _url = RemoteLinkAddress + _saveaddr;
			var _name = $("#ipt").val();
			var NAME = _type.toUpperCase() + "_" + "NAME";
			var map = getMap();
			//			Object data=getMap();
			map.put(_type.toUpperCase() + "_" + "NAME", _name);
			map.put("AUTHORIZATION", auth);
			map.put("SAVE_TYPE", "INSERT");

			console.log(NAME);
			if(_name != "") {
				$.ajax({
					type: "post",
					url: _url,
					data: map,
					dataType: "json",
					success:function(data)
					{
						if(data.msg=="success")
						{
							console.log("准备刷新");
							$('#dl').datalist('reload'); 
						}
						
					}
				});
				
			} else {
				$.messager.alert('Warning', '请输入数据!', 'info');
			}
			
		}

		function destroy() {
			var row = $('#dl').datalist('getSelected');
			if(row) {
				var _url1 = RemoteLinkAddress + _deleteaddr;
				var destroy_id = row[_id];
				var mapData = getMap();
				mapData.put("AUTHORIZATION", auth);
				mapData.put(_id, destroy_id);
				$.messager.confirm('Confirm', '是否删除', function(r) {
					if(r) {
						$.post(_url1, mapData,
							function(result) {
								if(result.msg == "success") {
									$('#dl').datalist('reload'); // reload the user data
									$.messager.alert({ // show error message
										title: '成功',
										msg: '删除成功'
									});
								} else {
									$.messager.alert({ // show error message
										title: 'Error',
										msg: result.msg
									});
								}
							},
							'json');
					}
				});
			} else {
				alert("未选中数据!");
			}
		}
	</script>

</html>